<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Sign in &laquo; Admin</title>
  <link rel="stylesheet" href=".././static/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href=".././static/assets/css/admin.css">
</head>
<body>
  <div class="login">
    <form class="login-wrap">
      <img class="avatar" src=".././static/assets/img/default.png">
      <!-- 有错误信息时展示 -->
      <div class="alert alert-danger" style="display:none">
           <strong>错误！</strong><span class="errorMsg"> 用户名或密码错误！</span>
      </div>
      <div class="form-group">
        <label for="email" class="sr-only">邮箱</label>
        <input id="email" type="text" class="form-control" placeholder="邮箱" autofocus>
      </div>
      <div class="form-group">
        <label for="password" class="sr-only">密码</label>
        <input id="password" type="password" class="form-control" placeholder="密码">
      </div>
      <input type="submit" class="btn btn-primary btn-block" value="登录">
    </form>
  </div>
</body>
<script src="../static/assets/vendors/jquery/jquery-1.12.2.min.js"></script>
<script>
      $(function(){
        $('.login-wrap').submit(function(){
          var email=$('#email').val();
          var pwd=$('#password').val();
            $.ajax({
               type:'post',
               data:{
                 "email":email,
                 "pwd":pwd
               },
                url:'./api/userLogin.php',
                dataType:'json',
                beforeSend:function(){
                  var reg=/\w+[@]\w+[.]\w+/;
                  if(!reg.test(email)){
                    $('.alert').show();
                    $('.errorMsg').html('请填写正确的邮件名');
                    return false;
                  };
                  if(pwd.trim()==''){
                    $('.alert').show();
                    $('.errorMsg').html('密码不能为空');
                    return false;
                  }
                },
                success:function(res){
                  console.log(res);
                   if(res.code==1){
                      location.href="index.php";
                   }else{
                     $('.alert').show();
                     $('.errorMsg').html('邮件名或者密码错误');
                   }
                }
   
            })
          return false;
        })
      })
   
</script>
</html>
